/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const TAG = 'zdy------>';
import hilog from '@ohos.hilog'


export class Logger {
    private static domain: number = 0x0001;
    private static tag: string = 'zdy';
    private static isDebug: boolean = true;
    private static isImportInfoNotShow: boolean = false; //重要日志信息是否不显示，用于日志分级，一般来说警告 错误 致命信息都需要显示，无论是debug嗨森正式环境，如果不需要显示则设置此参数为true.
    private static FORMAT: string = `%{public}s`;

    public static setDebug(debug: boolean) {
        this.isDebug = debug;
    }

    public static setTag(tagStr: string) {
        if (tagStr) {
            this.tag = tagStr;
        }
    }

    public static setDomain(domainValue: number) {
        if (domainValue) {
            this.domain = domainValue;
        }
    }

    public static setImportInfoNotShow(importInfoNotShow: boolean) {
        this.isImportInfoNotShow = importInfoNotShow;
    }

    public static log(...args: any) {
        if (this.isDebug && args) {
            hilog.info(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }

    public static debug(...args: any) {
        if (this.isDebug && args) {
            hilog.debug(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }


    public static info(...args: any) {
        if (this.isDebug && args) {
            hilog.info(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }

    public static warn(...args: any) {
        if (!this.isImportInfoNotShow && args) {
            hilog.warn(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }

    public static error(...args: any) {
        if (!this.isImportInfoNotShow && args) {
            hilog.error(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }

    public static fatal(...args: any) {
        if (!this.isImportInfoNotShow && args) {
            hilog.fatal(this.domain,this.tag, this.FORMAT, args.join('  '));
        }
    }
}
